// pages/tips/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    popShow: true,
    imgsrc: app.globalData.the_host + '/image/1233212212212/1576912659300839.png',
    fcode: '',
    xueliehao: '',
    vcode: '',
    data: [],
    city: '',
    county: '',
    idx: 0,
    name: '',
    imgurl: '',
    status: 0,
    message: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.showToast({
      title: '加载中..',
      icon: 'loading',
      //duration: 1500
    });
    this.getfcodedetect(options.fcode, options.vcode);

    var that = this
    that.setData({
      fcode: options.fcode,
      xuliehao: options.fcode.substring(12, 20),
      vcode: options.vcode,
      province: app.globalData.province,
      city: app.globalData.city,
      county: app.globalData.county,
      status: options.status,
    });
    console.log(this.data.city, this.data.county, this.data.fcode1)
  },
  //数据查询
  getfcodedetect: function(fcode, vcode) {
    wx.request({
      url: app.globalData.the_host + `/fcode/fcodedetect`,
      data: {
        "fcode": fcode,
        "vcode": vcode,
        "province": app.globalData.province,
        "city": app.globalData.city,
        "address": app.globalData.county,
        "lat": app.globalData.lat,
        "lng": app.globalData.lng,
        "openId": app.globalData.openId
      },

      header: {
        'content-type': 'application/json'
      },
      method: "POST",
      success: res => {
        console.log(res)
        if (res.statusCode == 200) {
          if (res.data.status == 0) {
            var img = ''
            for (let i = 0; i < res.data.data.resources.length; i++) {
              if (res.data.data.resources[i].type == 0) {
                img = res.data.data.resources[i].url;
                break
              }
            }
            this.setData({
              data: res.data.data,
              imgurl: img
            })
          }else if(this.data.status==30){
            this.setData({
              message: "扫描成功，解密失败，请重新扫描"
            })
          } else {
            this.setData({
              status: 1,
              message: res.data.message
            })
          }
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'success',
            duration: 2000,
          })
        }
        wx.hideToast(); //隐藏提示框
      }
    })
  },
  //跳转详情
  onClick: function() {
    //let code = JSON.stringify(this.data.data)
    wx.navigateTo({
      url: '../webview/index?fcode=' + this.data.fcode + "&vcode=" + this.data.vcode
    })
    // wx.navigateTo({
    //   url: '../webview/index?fcode=' + res.data.data.fcode + "&vcode=" + res.data.data.vcode
    // })
  },
  /**
  /**
    * 弹出层
    */

  // 打开弹窗
  popupTap: function(e) {
    this.setData({
      popShow: true
    })
  },

  // 这个函数内容为空 用于阻止屏幕滚动
  preventTouchMove: function(e) {},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})